/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "构建调试节点.h"
#include "../../ui节点视口.h"

#include <节点/调试/信息视图.h>



static void on_属性改变更新节点(S_Props& prop) {
	auto nodes = f_global_get激活节点();
	for (auto n : nodes) {
		n->f_set是否要更新(true);
	}
}



static void f_调试输出节点_3D视口更新(C_节点面板* node, S_Scene* scene) {
	C_调试输出节点* 网格节点 = dynamic_cast<C_调试输出节点*>(node->m_NodeData);

	//auto* ob = DEF_物体插座数据(网格节点->f_get输出插座(1), 0);
	//f_surface_创建实例((S_Mesh*)S_Core::g_当前独立显示物体->m_Data[1], (S_Mesh*)obs[0]->m_Data[0]);
	//f_surface_创建实例((S_Mesh*)S_Core::g_当前独立显示物体->m_Data[2], (S_Mesh*)obs[0]->m_Data[0]);
	//S_Core::g_当前独显物体类型 = E_物体类型::e_模型;
	//f_global_所在独显模型材质();
	((C_节点视口*)node->m_节点当前所在视口)->m_属性栏->m_绘制属性更新 = true;
	for (auto& e : 网格节点->m_Props) {
		//if(e.m_UI->m_Update) e.m_UI->m_Update(e);
		if(e.m_UI->m_部件) e.m_UI->m_部件->m_绘制属性更新 = true;
	}
}

static void f_调试输出节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_调试输出节点* node = dynamic_cast<C_调试输出节点*>(((C_节点面板*)obj)->m_NodeData);
	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);
	props.insert(props.end(), node->m_Props.begin(), node->m_Props.end());
	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_调试输出(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) {
		node = new C_调试输出节点(ctx_3d);
		if(node->m_ICO.empty()) node->m_ICO = "chat";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_调试输出(plane, node);
	return plane;
}

void f_节点重置_调试输出(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_节点视图);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_节点视图);

	plane->m_属性面板参数构建 = f_调试输出节点_部件构建属性;
	//plane->m_3D视口更新 = f_调试输出节点_3D视口更新;
	plane->m_ICO = node->m_ICO;
}












static void f_几何预览节点_3D视口更新(C_节点面板* node, S_Scene* scene) {
	C_几何预览节点* 节点 = dynamic_cast<C_几何预览节点*>(node->m_NodeData);

	return;
	uint8 num = 节点->m_Meshs.size();
	f_ob_set数据槽数量(S_框架::g_Debug物体, num);
	for (uint16 i = 0; i < num; ++i) {
		if (S_框架::g_Debug物体->m_Data[i] == nullptr) {
			S_框架::g_Debug物体->f_setData(f_surface_创建网格对象(E_网格数据枚举::e_Mesh_VULKAN), i);
		}
		f_surface_关联实例((S_Mesh*)S_框架::g_Debug物体->m_Data[i], 节点->m_Meshs[i]);

		//S_Core::g_VecSphere材质
		switch (节点->m_值类型[i])
		{
		case E_值类型::e_插座Type_八叉树:
		case E_值类型::e_插座Type_树路径: {
			f_ob_set材质(S_框架::g_Debug物体, S_框架::g_体素BOX材质, i);
			break;
		}
		
		case E_值类型::e_Type_Vec3: 
		case E_值类型::e_Type_Vec3_Array1D: {
			f_ob_set材质(S_框架::g_Debug物体, f_NodeCtx_get单色点材质(), i);
			break;
		}
		
		case E_值类型::e_Type_Vec4_Array1D: 
		case E_值类型::e_Type_VecSphere_1D: {
			f_ob_set材质(S_框架::g_Debug物体, S_框架::g_VecSphere材质, i);
			break;
		}
		case E_值类型::e_Type_Cube_Array1D:
			f_ob_set材质(S_框架::g_Debug物体, S_框架::g_Cube材质, i);
			break;

		case E_值类型::e_插座Type_Line_Array1D:
			f_ob_set材质(S_框架::g_Debug物体, S_框架::g_线段绘制材质, i);
			break;

		case E_值类型::e_Type_Object: {
			f_ob_set材质(S_框架::g_Debug物体, f_NodeCtx_get单色面材质(), i);
			break;
		}
		case E_值类型::e_Type_Mesh_1D:
		case E_值类型::e_Type_Mesh: {
			f_ob_set材质(S_框架::g_Debug物体, f_NodeCtx_get单色面材质(), i);
			break;
		}

		default:
			S_框架::g_Debug物体->f_关闭可视通道(i);
			continue;
		}

		S_框架::g_Debug物体->f_打开可视通道(i);
	}
	
	/*auto& mesh = *DEF_Mesh插座Value(节点->f_get输出插座(1), 0);
	if (nullptr != mesh.m_GPU网格) {
		f_surface_创建实例((S_Mesh*)S_Core::g_当前独立显示物体->m_Data[2], mesh.m_GPU网格);
		//f_ob_set材质(S_Core::g_当前独立显示物体, S_Core::g_体素BOX材质, 1);
	}
	S_Core::g_当前独显物体类型 = E_物体类型::e_模型;
	f_global_所在独显模型材质();*/
}

static void f_几何预览节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_几何预览节点* node = dynamic_cast<C_几何预览节点*>(((C_节点面板*)obj)->m_NodeData);

	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);

	plane->f_构建属性部件(props);

	f_几何预览节点_3D视口更新(((C_节点面板*)obj), nullptr);

}

C_节点面板* f_节点构建_几何预览(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) node = new C_几何预览节点(ctx_3d);
	//if (plane == nullptr) {
	//	plane = f_节点创建_UI面板构建(ctx, node, E_节点区类型::e_节点区_节点视图);
	//}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_几何预览(plane, node);
	return plane;

}

void f_节点重置_几何预览(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板重构(plane, node, E_节点区类型::e_节点区_物体);
	f_节点重构_插座重构(plane, node, E_节点区类型::e_节点区_物体);

	plane->m_属性面板参数构建 = f_几何预览节点_部件构建属性;
	plane->m_ICO = "预览";
}



static void f_控制台输出节点_部件构建属性(C_属性栏* plane, S_结构对象指针 obj) {
	C_控制台输出节点* node = dynamic_cast<C_控制台输出节点*>(((C_节点面板*)obj)->m_NodeData);
	std::vector<S_Props> props;
	f_节点重构_重构属性面板数据((C_节点面板*)obj, props);
	node->m_字符串.m_UI->m_Update = on_属性改变更新节点;
	props.push_back(node->m_字符串);
	plane->f_构建属性部件(props);
}

C_节点面板* f_节点构建_控制台输出节点(S_UI创建环境& ctx, S_设备环境& ctx_3d, C_节点基类* node, C_节点树* tree) {
	if (!node) {
		node = new C_控制台输出节点(ctx_3d);
		node->m_ICO = "ico取成员0011";
	}
	C_节点面板* plane = new C_节点面板(node, ctx, E_节点区类型::e_节点区_物体);
	f_节点重置_控制台输出节点(plane, node);
	return plane;
}

void f_节点重置_控制台输出节点(C_节点面板* plane, C_节点基类* node) {
	f_节点重构_面板插座重构(plane, node, E_节点区类型::e_节点区_节点视图);
	plane->m_属性面板参数构建 = f_控制台输出节点_部件构建属性;
	plane->m_ICO = node->m_ICO;
}







